package org.practice.tags;

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
/**
 * 标签处理类
 * 在 JSP2.0以前，所有标签处理类都必须实现 Tag 接口，这样的标签称为传统标签.
 * JSP2.0规范又定义了一种新的类型的标签，称为简单标签，其对应的处理类要实现 SimpleTag 接口
 */
public class MessageTag extends TagSupport{
	private String key;
	@Override
	public int doStartTag() throws JspException {
		super.doStartTag();
		JspWriter out=this.pageContext.getOut();
		ServletContext application=this.pageContext.getServletContext();
		Map<?,?> map=(Map<?,?>)application.getAttribute("msgMap_key");
		//Map<String,String> map=(Map<String,String>)application.getAttribute("msgMap_key");
		if(map!=null){
			String value=(String)map.get(key);
			if(value!=null){
				try {
					out.write(value);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		return 0;
	}
	public String getKey() {
		return key;
	}
	public void setKey(String key) {
		this.key = key;
	}
	
}
